<?php 
namespace api\home\controller;
use Weixin\weixin;
use cmf\controller\RestBaseController;
use think\Config;
class WeiXinController extends RestBaseController{
	public $AppID;
	public $AppSecret;
	public function __construct(){
		$this->AppID = Config::get('WAppId');
		$this->AppSecret = Config::get('WAppSecret');
	}
	#获取用户code
	public function getCode(){
		$weixin = new weixin($this->AppID,$this->AppSecret);
		$data['code'] = 200;
		$data['url'] = $weixin->getCode('https://sell.wengcong.cn/api/home/wei_xin/getUserInfo'); //传入回掉地址
		$this->success('success',$data);
	}
	#得到code去授权
	public function getUserInfo(){
		$codes = input('get.code');
		if($codes == ''){
			$data['code'] = 500;
			$this->error('error',$data);
		}else{
			$weixin = new weixin($this->AppID,$this->AppSecret);
			$data = $weixin->getUserInfo($codes);
			$data = json_decode($data,true);
			$data['code'] = 200;

			#数据结构 成功   失败对照文档
			#access_token	接口调用凭证
			#expires_in	access_token接口调用凭证超时时间，单位（秒）
			#refresh_token	用户刷新access_token
			#openid	授权用户唯一标识
			#scope	用户授权的作用域，使用逗号（,）分隔
			#unionid	当且仅当该网站应用已获得该用户的userinfo授权时，才会出现该字段。
			
			$this->error('success',$data);
		}
	}
}